package javabasics.concurrent.guardedsuspension;

/**
 * @Author suxiaoxiao
 * @Date 2019/6/16 13:46
 * @Version 1.0
 */
public class ClientThread extends Thread {
    // 请求队列
    private RequestQueue requestQueue;

    public ClientThread(RequestQueue requestQueue, String name) {
        super(name);
        this.requestQueue = requestQueue;
    }

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            Request request =
                    new Request(
                            "RequestID:" + i + " Thread_Name:" + Thread.currentThread().getName());
            System.out.println(Thread.currentThread().getName() + "requests " + request);
            // 提交请求
            requestQueue.addRequest(request);
            try {
                // 客户端请求的速度，快于服务端处理的速度。
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("ClientThread Name is:" + Thread.currentThread().getName());
        }
        System.out.println(Thread.currentThread().getName() + " request end");
    }

}
